package P4树形结构;
import java.util.Comparator;
import java.util.PriorityQueue;
/*
8 4 6 2 3 1 5
6 4 5 2 3 1
* */
public class TestPriorityQueue {
    public static void main(String[] args) {
        //java.util.PriorityQueue 默认最小堆
        //主要解决前K个元素之类的问题
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        queue.offer(3);
        queue.offer(2);
        queue.offer(1);
        queue.offer(8);
        queue.offer(4);
        queue.offer(6);
        queue.offer(5);
        for (Integer num : queue) {
            System.out.println(num);
        }
        System.out.println(queue.poll());
        for (Integer num : queue) {
            System.out.println(num);
        }
    }
}